<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="../../laydate/laydate.js"></script>
  <script type="text/javascript" src="../../js/jquery.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <script type="text/javascript" src="../../js/axios.js"></script>
  <script src="../../js/commons/react.js"></script>
  <script src="../../js/commons/reactDom.js"></script>
  <script src="../../js/commons/babel.js"></script>
  <script src="../../js/commons/antd.js"></script>
  <link href="../../css/antd.css" rel="stylesheet">
</head>

<body>
<form action="" id="fomm3">
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>入库管理</li>
    <li>添加入库</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>入库信息</span></div>
  <ul class="forminfo">
    <li id="xqbq">
      <label>采购单编号</label>
<!--      <input name="" type="text" class="dfinput" />-->
      <div tabindex="-1" hidefoucs="true" id="select" style="display: inline-block;position: relative;"></div>
      &nbsp;&nbsp
      <a href="../../purchase/purchase/purchaseView.html" title="点击查看采购单详细信息" class="tablelink" id="xq">详情</a>
      <i>必须是审核通过的采购单</i>
    </li>
    <li>
      <label>入库</label>
      <select class="dfselect" id="c2" name="warehouseId">
          <option>请选择</option>
          <option>南京21号仓库</option>
          <option>武汉71号仓库</option>
          <option>天津83号仓库</option>
      </select>
      <i>必选</i>
    </li>
    <li>
      <label>入库时间</label>
      <input name="rkDate" type="text" class="dfinput laydate-icon" id="time"/>
      <i>必填</i>
    </li>
    <li>
      <label>入库人</label>
      <input name="userId" id="uId" type="hidden" value="8" readonly="readonly" class="roinput" />
      <input id="username"  type="text" value="8" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    <li>
      <label>&nbsp;</label>
      <input name="" type="button" class="btn" id="btn" value="确认"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='stockList.html'"/>
    </li>
  </ul>
</div>
</form>
</body>
<script type="text/javascript">
  var start = {
    elem: '#time',
    format: 'YYYY-MM-DD hh:mm:ss',
    max: '2099-06-16', //最大日期
    istime: true,
    istoday: false,
    choose: function(datas){

    }
  };

  laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
  laydate(start);
</script>

<script type="text/babel">
  const Tree = () => {
    const fieldNames = { label: 'label', value: 'value' }
    const [selectedItems, setSelectedItems] = React.useState([]);
    const [OPTIONS,setOptions] = React.useState(['Apples', 'Nails', 'Bananas', 'Helicopters']);
    const filteredOptions = OPTIONS.filter((o) => !selectedItems.includes(o))


    React.useEffect(() => {

      axiosRequest("post","/warehouse/rkDetail",null).then((res)=>{
                let data2=[]
                const {data} =res.data.resultData
                for (let i = 0; i < data.length; i++) {
                  data2[i] = data[i].purchaseId
                }
                setOptions(data2)
              });

    }, [])

    const handleChange = (value) => {
      setSelectedItems(value)

      // var  li = "<label>采购单编号</label>\n" +
      //         "<!--      <input name=\"\" type=\"text\" class=\"dfinput\" />-->\n" +
      //         "      <div tabindex=\"-1\" hidefoucs=\"true\" id=\"select\" style=\"display: inline-block;position: relative;\"></div>\n" +
      //         "      &nbsp;&nbsp"+
      //         "<a href=\"./purchaseView2.html?purchaseId="+value[0]+"\" title=\"点击查看采购单详细信息\" class=\"tablelink\" id=\"xq\">详情</a>\n"+
      //         "<i>必须是审核通过的采购单</i>"
      // $("#xqbq").html(li);
      document.getElementById("xq").href = "./purchaseView2.html?purchaseId="+value[0]
      if (value.length===0){
        document.getElementById("xq").style.visibility = "hidden"
      }else{
        document.getElementById("xq").style.visibility = "visible"
      }
    };

    document.getElementById('btn').onclick = ()=>{
      var a1 = selectedItems.length
      var a2 = $("#c2").val()
      var a3 = $("#time").val()
      console.log(typeof a2)
      console.log(a2)
      console.log(typeof a1)
      console.log(a1)
      console.log(typeof a3)
      console.log(a3)

      if (a2!="0"&&a1!=0&&a3!=""){
          var data = $("#fomm3").serialize();
          data += "&rkIndent="+selectedItems[0];

          axiosRequest("post","/warehouse/addRK",data)
                  .then((res)=>{
                    alert("插入成功")
                    window.location.href='./stockList.html'
                    axiosRequest("post","/warehouse/caigao",data)
                            .then((res)=>{

                            })
                  })
      }else {
        alert("有未填项")
      }


    }


    return (<antd.Select
                    mode="multiple"
                    // showSearch
                    placeholder="Inserted are removed"
                    value={selectedItems}
                    onChange={handleChange}
                    style={{
                      width: 250,
                    }}
                    options={filteredOptions.map((item) => ({
                      value: item,
                      label: item,
                    }))}
            />
    )
  }

  ReactDOM.createRoot(document.querySelector('#select')).render(<Tree />)
</script>

<script type="text/javascript">
  $(function () {
    $('#uId').val(localStorage.getItem("uId"))
    $('#username').val(localStorage.getItem("username"))
    $("#xq").css("visibility","hidden")
    queryWare();
  });
  function queryWare() {
    axiosRequest("post","/warehouse/queryWareAll",null)
            .then((res)=>{
              var lis = "<option value='0' selected>请选择</option>";
              for (var i = 0; i < res.data.length; i++) {
                var li = "<option value='"+res.data[i].id+"'>"+res.data[i].cName+"</option>"
                lis+=li;
              }
              $("#c2").html(lis)
            });
  }


</script>
</html>